package com.example.voip;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;

import com.example.widget.CallDialog;

@SuppressWarnings("deprecation")
public class IndexActivityOld extends TabActivity implements OnCheckedChangeListener{
	
	private TabHost mHost;
	private RadioGroup radioderGroup;
	private RadioButton radio0, radio1, radio2;
	private DisplayMetrics metrics;
	private CallDialog cd = null;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.bottom_tab);
		metrics = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(metrics);
		radio0 = (RadioButton) findViewById(R.id.radio_button0);
		radio1 = (RadioButton) findViewById(R.id.radio_button1);
		radio2 = (RadioButton) findViewById(R.id.radio_button2);
		
		mHost = this.getTabHost();
		mHost.addTab(mHost.newTabSpec("ONE").setIndicator("ONE").setContent(new Intent(this, MainActivity.class)));
		mHost.addTab(mHost.newTabSpec("TWO").setIndicator("TWO").setContent(new Intent(this, MoreActivity.class)));
		radioderGroup = (RadioGroup) findViewById(R.id.main_radio);
		radioderGroup.setOnCheckedChangeListener(this);
		mHost.setCurrentTabByTag("ONE");
		radio1.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				radioderGroup.measure(View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED));
				if(cd != null){
					if(cd.isShowing()){
						cd.cancel();
					}else{
						cd.show();
					}
				}else{
					cd = new CallDialog(IndexActivityOld.this, metrics, radioderGroup.getMeasuredHeight());
					cd.show();
				}
			}
		});
	}

	@Override
	public void onCheckedChanged(RadioGroup group, int checkedId) {
		switch (checkedId) {
		case R.id.radio_button0:
			mHost.setCurrentTabByTag("ONE");
			break;
		case R.id.radio_button2:
			mHost.setCurrentTabByTag("TWO");
			break;
		}
	}

}
